package controllers

import (
	//"fmt"
	"github.com/astaxie/beego"
)

type LoginController struct {
	beego.Controller
}

func (login *LoginController) Get() {
	login.TplName = "login.html"
}

func (login *LoginController) Post() {
	uname := login.Input().Get("username")
	pwd := login.Input().Get("userpassword")
	autoLogin := login.Input().Get("autologin") == "on"

	if beego.AppConfig.String("username") == uname &&
		beego.AppConfig.String("userpassword") == pwd {
		maxAge := 0
		if autoLogin {
			maxAge = 1<<31 - 1
		}
		login.Ctx.SetCookie("username", uname, maxAge, "/")
		login.Ctx.SetCookie("password", pwd, maxAge, "/")
	}
	login.Redirect("/", 301)
	return
}
